﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace Simulator
{
	class MstConfigEditor : UITypeEditor
	{
		public override UITypeEditorEditStyle GetEditStyle (ITypeDescriptorContext context) 
		{
			return UITypeEditorEditStyle.Modal;
		}

		public override object EditValue (ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			IWindowsFormsEditorService svc = (IWindowsFormsEditorService) provider.GetService (typeof (IWindowsFormsEditorService));
			MstConfigId foo = (MstConfigId) value;
			if (svc != null && foo != null)
			{
				if (foo.Bridge.ForceProtocolVersion < STP.StpVersion.MSTP)
				{
					MessageBox.Show ("MST Config ID is available only for bridges running MSTP");
				}
				else
				{
					using (var form = new MstConfigIdForm (foo.Bridge))
					{
						var dr = svc.ShowDialog (form);
						//	//if (dr == System::Windows::Forms::DialogResult::OK)
						//	//{
						//	//	MessageBox::Show ("TODO: change bridge object only here");
						//	//}
					}
				}
			}
			else
				throw new NotImplementedException ();

			return value; // can also replace the wrapper object here
		}
	};

	[Editor (typeof (MstConfigEditor), typeof (UITypeEditor))]
	[TypeConverter (typeof (ExpandableObjectConverter))]
	public class MstConfigId
	{
		public readonly Bridge Bridge;

		public MstConfigId (Bridge bridge)
		{
			this.Bridge = bridge;
		}

		public string Name
		{
			get { return Bridge.Wrapper.GetMstConfigName (); }
		}
	}
}
